<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/30
 * Time: 15:10
 */

namespace app\admin\model;


class OrderModel extends BaseModel
{
    protected $table = "xst_order";
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
    public function orderlist(){//订单显示
        $list=$this
            ->join('xst_user','xst_user.id=xst_order.uid','left')
            ->order('createtime desc')
            ->field('xst_order.*,xst_user.nickname')
            ->paginate(10);

        return $list;
    }
    public function getOneId($id){//获取要修改的信息
        return $this
            ->join('xst_user u','u.id=xst_order.uid')
            ->where('xst_order.id',$id)
            ->find();
    }
    public function orderupdate(){//修改订单信息
        $order_number = request()->post('order_number');
        //$uid = request()->post('uid');
        $commodity_id = request()->post('commodity_id');
        $name = request()->post('name');
        $specification = request()->post('specification');
        $price = request()->post('price');
        $status = request()->post('status');
        $paytime = request()->post('paytime');
        $id = request()->post('uid');
        return $this->where('id',$id)->update([
            'order_number'=>$order_number,
            //'uid'=>$uid,
            'commodity_id'=>$commodity_id,
            'name'=>$name,
            'specification'=>$specification,
            'price'=>$price,
            'status'=>$status,
            'paytime'=>$paytime,
            'createtime'=>time()
        ]);
    }
    public function add(){//订单添加
        $order_number = request()->post('order_number');
        $uid = request()->post('uid');
        $commodity_id = request()->post('commodity_id');
        $name = request()->post('name');
        $specification = request()->post('specification');
        $price = request()->post('price');
        $status = request()->post('status');
        $paytime = request()->post('paytime');
        return $this->insert([
            'order_number'=>$order_number,
            'uid'=>$uid,
            'commodity_id'=>$commodity_id,
            'name'=>$name,
            'specification'=>$specification,
            'price'=>$price,
            'status'=>$status,
            'paytime'=>$paytime,
            'createtime'=>time()
        ]);
    }
    public function del()//删除订单信息
    {
        $id = request()->post('id');
        return $this->where('id',$id)->delete();
    }
    public function dell(){
        $id = request()->post('id');
        return $this->where('id','in',$id)->delete();
    }
}